package com.dlyk.web;

import com.dlyk.model.TranRemark;
import com.dlyk.query.TranRemarkQuery;
import com.dlyk.result.R;
import com.dlyk.service.TranRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 交易备注
 */
@RestController
public class TranRemarkController {

    @Resource
    private TranRemarkService tranRemarkService;

    /**
     * 添加交易备注
     */
    @PostMapping("/api/tran/remark/add")
    public R addTranRemark(@RequestBody TranRemarkQuery tranRemarkQuery) {

        int add = tranRemarkService.addTranRemark(tranRemarkQuery);

        return add >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 加载交易备注列表（分页查询）
     */
    @GetMapping("/api/tran/remark/list")
    public R tranRemarkList(@RequestParam(value = "current", required = false) Integer current) {

        // required = false  表示非必须，这个参数也可以不传，不传参数，默认查询第一页
        if (current == null) {
            current = 1;
        }

        PageInfo<TranRemark> tranRemarkPageInfo = tranRemarkService.getTranRemarkListByPage(current);

        return R.OK(tranRemarkPageInfo);
    }

    /**
     * 编辑交易备注
     */
    @PutMapping("/api/tran/remark/edit")
    public R editTranRemark(@RequestBody TranRemarkQuery tranRemarkQuery) {

        int edit = tranRemarkService.editTranRemark(tranRemarkQuery);

        return edit >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 删除交易备注（逻辑删除）
     */
    @DeleteMapping("/api/tran/remark/remove/{id}")
    public R removeTranRemark(@PathVariable Integer id) {

        int remove = tranRemarkService.removeTranRemarkById(id);

        return remove >= 1 ? R.OK() : R.FAIL();
    }

}

